﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;
using ClientSite2nd.Models;

namespace ClientSite2nd.Logic
{
    public class SessionWrapper
    {
        public static Client CurrentClient
        {
            get
            {
                if (HttpContext.Current.Session["Client"] == null)
                {
                    var membershipUser = Membership.GetUser();
                    HttpContext.Current.Session["Client"] = new ClientContext()
                        .Clients
                        .SingleOrDefault(c => c.Id == (Guid)membershipUser.ProviderUserKey);
                }
                return (Client)HttpContext.Current.Session["Client"];
            }
        }

        public static void Finagle()
        {
            HttpContext.Current.Session["Client"] = null;
        }
    }
}